<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const posts=[
            {title:'I js',author:'yy',id:1},
            {title:'I jss',author:'yys',id:2},
        ]
        // console.log(JSON.stringify(posts));
        // posts.push({
        //     title:'webpack',
        //     author:'sss',
        //     id:3
        // })
        // // localStorage.setItem(JSON.stringify(posts));
        // // const authors=[
        // //     {name:'yy',hometown:'gg',bio:'ssssw'}
        // // ]
        function getPostById(id){
            // const post =posts.find(post =>post.id===id);
            // const {author}=post;
            // // 
            
            // console.log(authors.find(item=>item.name==author));
            // return post;
            return new Promise((resolve,reject)=>{
                // resolve();
                console.log('11111111111');
                setTimeout(()=>{
                    const post=posts.find(post =>post.id===id);
                    console.log(post);
                    if(post){
                        resolve(data);
                    }else{
                        let err=new Error('没有数据');
                        reject(err);
                    }
                    // resolve();
                },200)
            });
        }
        getPostById(10)
            .then((data)=>{
                console.log(data,'//////////');
            })
            .catch((err)=>{
                console.log(err.message);
            })
    </script>
</body>
</html>